<template>
  <div class="LoginBackground">
    <router-link to="/index"
      ><van-icon name="arrow-left" class="back"
    /></router-link>
    <div class="main">
      <h2 class="title">欢迎来到星迹</h2>
      <van-form class="login">
        <van-icon name="user-circle-o" class="user" />
        <van-field
          class="username"
          v-model="username"
          name="用户名"
          placeholder="请输入账号"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-icon name="lock" class="lock" />
        <van-field
          v-model="password"
          type="password"
          class="username"
          name="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" @click="submit" class="submit"
            >登录</van-button
          >
        </div>
      </van-form>
      <slot></slot>
    </div>
  </div>
</template>

<script>
import { Login } from "@/api/api";

export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    submit() {
      Login(this.username, this.password)
        .then((res) => {
          if (res.data.code == 0) {
            this.$store.commit("changeUserInfo", {
              isLogin: true,
              userInfo: res.data,
            });
            this.$router.go(-1);
            //res.msg
            this.$message.success("登录成功！");
          } else {
            this.$message.error(`${res.data.msg}`);
          }
        })
        .catch((res) => {
          this.$message.error(`网络繁忙，请稍后再试。。。。`);
        });
    },
  },
};
</script>

<style scoped lang="less">
.LoginBackground {
  background: url("https://cdn.jsdelivr.net/gh/recreyed/blogImg/luntan/ANIME-PICTURES.NET_-_519307-1447x2047-kimi+no+na+.png")
    center center no-repeat;
  background-size: cover;
  height: 100vh;
}
.back {
  font-size: 30px;
  margin: 15px;
  color: white;
}
.main {
  margin-top: 40%;
  overflow: hidden;
  padding-bottom: 35%;
  .title {
    text-align: center;
    font-size: 30px;
    font-weight: 700;
    margin-bottom: 50px;
    color: white;
  }

  .login {
    position: relative;

    .username {
      width: 80%;
      height: 60px;
      background-color: #eeeeee;
      border-radius: 30px;
      margin: 10px auto;
      line-height: 40px;
      padding-left: 50px;
    }

    .user {
      z-index: 10;
      position: absolute;
      top: 18px;
      left: 58px;
      font-size: 25px;
    }

    .lock {
      z-index: 10;
      position: absolute;
      top: 85px;
      left: 58px;
      font-size: 25px;
    }

    .submit {
      width: 80%;
      height: 60px;
      margin: 40px auto;
      background-color: black;
      outline: 0;
      border: 0;
    }
  }

  .register {
    float: left;
    margin-top: 20px;
    margin-left: 20px;
    color: white;
  }

  .forget {
    float: right;
    margin-right: 20px;
    margin-top: 20px;
    color: white;
  }
}
</style>